<template>
    <div class="tab-container">
        <!-- Tab 标题 -->
        <div class="tab-header">
            <div :style="{ color: videoType ? activeTab === index ? '#66CCFF' : '#fff' : '' }" v-for="(tab, index) in tabs"
                :key="index" class="tab-item" :class="{ active: activeTab === index }" @click="changeTab(index, tab)">
                {{ tab.name ? tab.name : tab }}{{ tab.nums ? tab.nums : '' }}
            </div>
            <!-- 底部滑块 -->
            <div class="slider" :style="sliderStyle">
                <div :style="{ backgroundColor: videoType ? 'rgb(102, 204, 255)' : '#1068E7'}"></div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'lTab',
    props: {
        tabs: {
            type: Array,
            default: () => {
                return [{ name: 'Tab 1', nums: 3, type: 2 }, 'Tab 1', 'Tab 1']
            },
        },
        videoType: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            activeTab: 0, // 当前选中的 Tab
        };
    },
    computed: {
        // 计算滑块的样式
        sliderStyle() {
            const tabWidth = 100 / this.tabs.length; // 每个 Tab 的宽度百分比
            return {
                width: `${tabWidth}%`, // 滑块的宽度
                transform: `translateX(${this.activeTab * 100}%)`, // 滑块的偏移量
            };
        },
    },
    methods: {
        // 切换 Tab
        changeTab(index) {
            this.activeTab = index;
            this.$emit('changeTab', index)
        },
    },
};
</script>

<style scoped>
.tab-container {
    padding: 30px 0;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    font-family: Arial, sans-serif;
}

.tab-header {
    display: flex;
    position: relative;
}

.tab-item {
    flex: 1;
    text-align: center;
    padding: 10px 0;
    cursor: pointer;
    transition: color 0.3s;
    font-weight: 400;
    font-size: 24px;
    color: #333333;
}

.tab-item.active {
    color: #1068E7;
    font-weight: bold;
    /* 选中 Tab 的文字颜色 */
}

.slider {
    position: absolute;
    bottom: -2px;
    height: 3px;
    box-sizing: border-box;
    padding: 0 22px;

    /* 滑块颜色 */
    transition: transform 0.3s ease-in-out;
    /* 滑块的动画效果 */
}
.slider>div{
    background-color: #1068E7;
    width: 100%;
    height: 3px;
}
.tab-content {
    padding: 20px;
    border: 1px solid #ddd;
    border-top: none;
}
@media screen and (max-width:768px) {
    .tab-container{
        max-width: none;
        padding: 10px 0;
    }
    .tab-item{
        font-size: 13px;
padding-bottom:  15px;
    }
}
</style>